package club.itstudio.IContainer.exception;

import club.itstudio.IContainer.util.Result;
import club.itstudio.IContainer.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(BaseException.class)
    public Result baseExceptionHandler(BaseException e) {
        return ResultUtil.error(e.status, e.errorMsg);
    }

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(RuntimeException.class)
    public Result runtimeExceptionHandler(RuntimeException e) {
        return ResultUtil.error(e.getMessage());
    }
}
